/**
 * 
 */
package org.o14x.alpha.ui.commands.newfile;

import java.io.File;

import org.eclipse.jface.dialogs.IInputValidator;
import org.o14x.alpha.util.Messages;

/**
 * Validates user input for file creation.
 * 
 * @author Olivier DANGREAUX
 */
public class NewFileInputValidator implements IInputValidator {
	File currentDirectory;

	NewFileInputValidator(File currentDirectory) {
		this.currentDirectory = currentDirectory;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
	 */
	@Override
	public String isValid(String newText) {
		String errorMessage = null;

		File newFile = new File(currentDirectory, newText);
		if (newFile.exists()) {
			errorMessage = Messages.getString("NewFileInputValidator.file_exists_message"); //$NON-NLS-1$
		}

		return errorMessage;
	}

}
